using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerState
{

    public Rigidbody2D rb;// 角色刚体
    protected PlayerStateMachine stateMachine;// 角色状态机
    protected Player player;// 角色脚本


    protected float xInput;// x轴输入
    protected float yInput;// y轴输入

    private string animBoolName;// 动画名称

    protected float stateTimer;// 状态计时器(冲刺、墙跳)
    protected bool triggerCalled;// 动画结束触发器

    public PlayerState(Player _player, PlayerStateMachine _stateMachine, string _animBoolName)
    {
        this.player = _player;// 为状态初始化选择主体
        this.stateMachine = _stateMachine;// 为状态初始化选择状态机
        this.animBoolName = _animBoolName;// 为状态初始化选择动画条件
    }

    public virtual void Enter()
    {
        player.anim.SetBool(animBoolName, true);// 进入状态时选择动画
        rb = player.rb;// 简写
        triggerCalled = false;// 设置动画未结束
    }

    public virtual void Update()
    {
        xInput = Input.GetAxisRaw("Horizontal");// 水平输入
        yInput = Input.GetAxisRaw("Vertical");// 垂直输入

        player.anim.SetFloat("yVelocity", rb.velocity.y);// 绑定y轴与动画

        // 计数器
        stateTimer -= Time.deltaTime;

    }

    public virtual void Exit()
    {
        player.anim.SetBool(animBoolName, false);// 退出状态时取消动画
    }


    public virtual void AnimationFinishTrigger()
    {
        triggerCalled = true;// 动画结束时触发
    }
}
